# -*- coding: utf-8 -*-
from flask import Flask, jsonify, request
from flask_cors import *
import json
from match import *
app = Flask(__name__, static_url_path='')
app.config['JSON_AS_ASCII'] = False
CORS(app, supports_credentials=True)
# 只接受POST方法访问


@app.route('/', methods=["GET"])
def index():
    return app.send_static_file('labeling.html')


@app.route('/results.json', methods=["GET", "POST"])
def showResults():
    text = ""
    if request.method == "POST":
        text = request.form['text']
    else:
        text = request.args['text']
    extractors = [HuiZuiExtractor, MoneyExtractor, GongTongExtractor, ShuZuiExtractor, DuPinBianHuExtractor,
                  QiangJieBianHuExtractor, GuYiShanHaiBianHuExtractor, ZiShouExtractor, LeiFanExtractor,
                  HuiZuiExtractor,
                  QianKeExtractor, DaoQieBianHuExtractor, WeiXianJiaShiBianHuExtractor, LiGongExtractor,
                  TanBaiExtractor, BeiHaiRenLiangJieExtractor, CangYuExtractor, RenZuiExtractor, ZhuDongPeiChangExtractor,
                  TuiZangExtractor, QiaoZhaBianHuExtractor, WeiXianBianHuExtractor, JiaoTongBianHuExtractor,
                  JiZiZhaPianBianHuExtractor, WeiFanJTFGExtractor, ZuoAnGongJuExtractor, ZuoAnDuiXiangExtractor,
                  GuYiShangHaiExtractor, daoqieExtractor, ZhuGuanEXingExtractor, ZuiJiuJiaShiExtractor]
    result_dict = {}
    for extractor in extractors:
        if extractor.is_my_job(text):
            result_dict.update(extractor.extract(text))
    # print(results)

    return jsonify(result_dict)


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5050, debug=True)
